// miniprogram/pages/my/index.js
import * as R from 'ramda';
import U from "../../utils/index";
import config from '../../config/index';
import { Either } from "../../utils/vendor/ramda-fantasy";
const globalData = getApp().globalData;

const validateRole = R.ifElse(
  R.either(R.equals(0), R.equals(1)),
  Either.Right,
  () => Either.Left('您没有权限!')
);
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: null,
    roleTypeName: null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      userInfo: globalData.userInfo,
      roleTypeName: config.roleTypes[globalData.userInfo.role],
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  logout() {
    U.logout().runIO();
  },
  onClickMember(e) {
    R.compose(
      U.runIO,
      U.handleError,
      R.map(() => wx.navigateTo({ url: 'member/index' })),
      validateRole
    )(globalData.userInfo.role)
  },
})
